package com.example.ruralservicedigitalplatform.comment;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result<T> {
    private Integer code;//响应码，200 代表成功; 201 代表审核; 0 代表失败
    private String msg;  //响应信息 描述字符串
    private T data; //返回的数据

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

    public Result(Integer code, T data) {
        this(code, "success", data);
    }

    public Result(Integer code, String message) {
        this(code, "success", null);
    }

//    public Result(ErrorCode errorCode, String message) {
//        this(errorCode.getCode(),"success",null);
//    }
//
//    public Result(ErrorCode errorCode, T data) {
//        this(errorCode.getCode(),"success",data);
//    }
//
//    public Result(ErrorCode errorCode, String message, T data) {
//        this(errorCode.getCode(),"success",data);
//    }
//
//    public Result(ErrorCode errorCode) {
//        this(errorCode.getCode(),"success",null);
//    }

    //增删改 成功响应
    public static Result success() {
        return new Result(200, "success", null);
    }

    //查询 成功响应
    public static Result success(Object data) {
        return new Result(200, "success", data);
    }

    //失败响应
    public static Result error(String message) {
        return new Result(0, message, null);
    }

    //审核
    public static Result examine(String message, Object data) {
        return new Result(201, message, data);
    }
}
